package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

/**
 * 精品PK一项
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_competing_products_pk)
public class CompetingProductsPKItemView extends LinearLayout {
    @ViewById
    ImageView itemCompetingProductsImage1, itemCompetingProductsImage2;
    @ViewById
    TextView itemPoWoDictionaryTitleText;


    public CompetingProductsPKItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public CompetingProductsPKItemView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Click(R.id.itemRootView)
    public void enterNewsDetail() {
        Intent intent = new Intent();
        intent.setClassName(getContext(),
                Constants.NEWSDETAILACTIVITY_CLASS_NAME);
        intent.putExtra("title", "竞品PK");
        getContext().startActivity(intent);
    }

    /**
     * 加载数据
     *
     * @param itemJsonObject
     * @param position
     * @param displayImageOptions
     */
    public void loadData(JSONObject itemJsonObject, int position,
                         BitmapLoader bitmapLoader) {
        JSONArray productsArray = TypeUtils.getJsonArray(itemJsonObject,
                "products");
        itemPoWoDictionaryTitleText.setText(TypeUtils.getJsonString(
                productsArray, 0)
                + " VS  "
                + TypeUtils.getJsonString(productsArray, 1));

        JSONArray imagesArray = TypeUtils
                .getJsonArray(itemJsonObject, "images");
        // ImageLoader.getInstance().displayImage(
        // TypeUtils.getJsonString(imagesArray, 0),
        // itemCompetingProductsImage1, displayImageOptions);
        //
        bitmapLoader.displayImage(TypeUtils.getJsonString(imagesArray, 0),
                itemCompetingProductsImage1);

        // ImageLoader.getInstance().displayImage(
        // TypeUtils.getJsonString(imagesArray, 1),
        // itemCompetingProductsImage2, displayImageOptions);

        bitmapLoader.displayImage(TypeUtils.getJsonString(imagesArray, 1),
                itemCompetingProductsImage2);

    }
}
